gtkwindow: Add private API to update pointer cursors
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 4 Apr 2017 15:08:48 +0000 (17:08 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Thu, 25 May 2017 14:25:59 +0000 (16:25 +0200)
gtk/gtkwindow.c
gtk/gtkwindowprivate.h

index 5531ccd6b7f42fe2bb28c0ceaea780c3b0f50a6f..c9ca7faef6b47a55f6c98b8853fd6ccae02e496f 100644 (file)
@@ -11383,3 +11383,56 @@ gtk_window_set_pointer_focus_grab (GtkWindow        *window,
   g_assert (focus != NULL);
   gtk_pointer_focus_set_implicit_grab (focus, grab_widget);
 }
+
+static void
+update_cursor (GtkWindow *toplevel,
+               GdkDevice *device,
+               GtkWidget *target)
+{
+  GdkCursor *cursor = NULL;
+  GList *widgets = NULL, *l;
+
+  while (target)
+    {
+      widgets = g_list_prepend (widgets, target);
+      target = _gtk_widget_get_parent (target);
+    }
+
+  for (l = widgets; l; l = l->next)
+    {
+      cursor = gtk_widget_get_cursor (l->data);
+      if (cursor)
+        break;
+    }
+
+  gdk_window_set_device_cursor (gtk_widget_get_window (GTK_WIDGET (toplevel)),
+                                device, cursor);
+  g_list_free (widgets);
+}
+
+void
+gtk_window_maybe_update_cursor (GtkWindow *window,
+                                GtkWidget *widget,
+                                GdkDevice *device)
+{
+  GList *l = window->priv->foci;
+
+  for (l = window->priv->foci; l; l = l->next)
+    {
+      GtkPointerFocus *focus = l->data;
+
+      if (focus->sequence)
+        continue;
+      if (device && device != focus->device)
+        continue;
+
+      if (widget != focus->target &&
+          !gtk_widget_is_ancestor (focus->target, widget))
+        continue;
+
+      update_cursor (focus->toplevel, focus->device, focus->target);
+
+      if (device)
+        break;
+    }
+}
index 857121985ec6d79d14b3cab766208a26a6dadc2f..1d97de7a1a3828e7b6d22189199cc231dc172c85 100644 (file)
@@ -164,6 +164,9 @@ void             gtk_window_update_pointer_focus_on_state_change (GtkWindow *win
 void             gtk_window_maybe_revoke_implicit_grab (GtkWindow *window,
                                                         GdkDevice *device,
                                                         GtkWidget *grab_widget);
+void             gtk_window_maybe_update_cursor (GtkWindow *window,
+                                                 GtkWidget *widget,
+                                                 GdkDevice *device);
 
 G_END_DECLS